/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.cellstore.cliente.gui;

import java.awt.Component;
import java.util.List;
import javax.swing.DefaultListCellRenderer;
import javax.swing.JList;
import org.cellstore.controlador.CellStoreController;
import org.cellstore.cliente.gui.model.Columna;
import org.cellstore.cliente.gui.model.ModoFormulario;
import org.cellstore.entidad.TbSystpar;
import org.cellstore.entidad.TbSystparPK;
import org.jdesktop.beansbinding.Binding;
import org.palituxd.tools.mensaje.Mensaje;
import org.cellstore.spring.Spring;

/**
 *
 * @author PPATOCHE
 */
public class IFMantenimientoV2 extends javax.swing.JInternalFrame {

    /**
     * Creates new form IFMantenimiento
     */
    private CellStoreController cellStoreController;
    private ModoFormulario poModFor;

    public IFMantenimientoV2() {
        cellStoreController = Spring.getInstance().getController();
//        cargarColumnas();

        initComponents();
        cargarCombo();


//        cargarDatos();
//        modeloTabla1.setLista(obtenerTodosTbSystpar);
        this.mxModoFormulario(ModoFormulario.INICIO);
    }

    private void cargarCombo() {
        List<TbSystpar> obtenerTablaTbSystpar = cellStoreController.obtenerTablaTbSystpar("001");
        List resultList = LstBeanModulo.getResultList();
        resultList.clear();
        resultList.addAll(obtenerTablaTbSystpar);
        Binding binding = bindingGroup.getBinding("combo");
        binding.unbind();
        binding.bind();
        cbModulo.revalidate();
    }

//    private void cargarColumnas() {
////        ArrayList<Columna> listaColumnas = new ArrayList<Columna>();
////        listaColumnas.add(new Columna("A", "campoa", Integer.class, false, 100, 50, null));     
//        modelo = new Modelo(listaColumnas);
//    }
//    private void cargarDatos() {
//        List<TbSystpar> obtenerTodosTbSystpar = cellStoreController.obtenerTodosTbSystpar();
//        list2.addAll(obtenerTodosTbSystpar);
//    }
    private void mxModoFormulario(ModoFormulario toModFor) {
        this.poModFor = toModFor;
        this.btnGuardar.setEnabled(false);
        this.btnNuevo.setEnabled(true);
        this.btnDeshacer.setEnabled(false);
        this.btnEditar.setEnabled(false);
        this.tabPrincipal.setSelectedComponent(tabBusqueda);
        this.tabPrincipal.setEnabledAt(0, true);
        this.tabPrincipal.setEnabledAt(1, false);

        switch (toModFor) {
            case INICIO:
            case DESHACER:
            case GUARDAR:
                break;
            case EDICION:
                this.tabPrincipal.setTitleAt(1, "Edición");
                this.btnGuardar.setEnabled(true);
                this.btnNuevo.setEnabled(false);
                this.btnDeshacer.setEnabled(true);
                this.btnEditar.setEnabled(false);
                this.tabPrincipal.setSelectedComponent(tabEdicion);
                this.tabPrincipal.setEnabledAt(0, false);
                break;
            case NUEVO:
                this.tabPrincipal.setTitleAt(1, "Nuevo");
                this.btnGuardar.setEnabled(true);
                this.btnNuevo.setEnabled(false);
                this.btnDeshacer.setEnabled(true);
                this.btnEditar.setEnabled(false);
                this.tabPrincipal.setSelectedComponent(tabEdicion);
                this.tabPrincipal.setEnabledAt(0, false);
                break;
            case SELECCION:
                this.btnEditar.setEnabled(true);
                break;
            default:
                break;
        }
    }

    private void setModoEdicion(boolean editable) {
//        txtAbreviatura.setEnabled(true);
//        txtBusqueda.setEnabled(true);
//        txtDescripcion.setEnabled(true);
//        txtId.setEnabled(true);
//        txtValor.setEnabled(true);
    }

    private void limpiarDatos() {
//        txtAbreviatura.setText("");
//        txtBusqueda.setText("");
//        txtDescripcion.setText("");
//        txtId.setText("");
//        txtValor.setText("");
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        beanLista1 = new org.cellstore.cliente.gui.model.BeanLista();
        LstBeanModulo = new org.cellstore.cliente.gui.model.BeanLista();
        list1 = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : org.jdesktop.observablecollections.ObservableCollections.observableList(beanLista1.getResultList());
        LstModulo = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : org.jdesktop.observablecollections.ObservableCollections.observableList(LstBeanModulo.getResultList());
        pPrincipal = new javax.swing.JPanel();
        pCentro = new javax.swing.JPanel();
        tabPrincipal = new javax.swing.JTabbedPane();
        tabBusqueda = new javax.swing.JPanel();
        pBuscar = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        cbBusqueda = new javax.swing.JComboBox();
        txcBusqueda = new org.palituxd.tools.swing.CTextField();
        btnBusqueda = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tbParametro = new javax.swing.JTable();
        tabEdicion = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        txcCodTab = new org.palituxd.tools.swing.CTextField();
        txcCodigo = new org.palituxd.tools.swing.CTextField();
        txnOrden = new org.palituxd.tools.swing.CTextField();
        txcDesCor = new org.palituxd.tools.swing.CTextField();
        txcDesLar = new org.palituxd.tools.swing.CTextField();
        txcValor = new org.palituxd.tools.swing.CTextField();
        jLabel11 = new javax.swing.JLabel();
        txcCodIns = new org.palituxd.tools.swing.CTextField();
        jLabel12 = new javax.swing.JLabel();
        txcValMin = new org.palituxd.tools.swing.CTextField();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        txcValMax = new org.palituxd.tools.swing.CTextField();
        chkValidar = new javax.swing.JCheckBox();
        chkActivar = new javax.swing.JCheckBox();
        txcObserv = new org.palituxd.tools.swing.CTextField();
        jLabel15 = new javax.swing.JLabel();
        cbModulo = new javax.swing.JComboBox();
        jPanel2 = new javax.swing.JPanel();
        jPanel6 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        jLabel8 = new javax.swing.JLabel();
        btnCargaImagen = new javax.swing.JButton();
        pSur = new javax.swing.JPanel();
        jPanel5 = new javax.swing.JPanel();
        btnGuardar = new javax.swing.JButton();
        btnNuevo = new javax.swing.JButton();
        btnEditar = new javax.swing.JButton();
        btnDeshacer = new javax.swing.JButton();
        btnSalida = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        lblCodigoVentana = new javax.swing.JLabel();

        setClosable(true);
        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setIconifiable(true);
        setTitle("[Mantenimiento]");
        setFrameIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/Application-Default-Orange-16.png"))); // NOI18N
        setMinimumSize(new java.awt.Dimension(410, 370));
        setNormalBounds(new java.awt.Rectangle(0, 0, 0, 0));
        setPreferredSize(new java.awt.Dimension(410, 370));
        addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameClosing(evt);
            }
            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
            }
        });
        getContentPane().setLayout(new java.awt.GridBagLayout());

        pPrincipal.setPreferredSize(new java.awt.Dimension(200, 448));
        pPrincipal.setLayout(new java.awt.BorderLayout(0, 5));

        pCentro.setLayout(new java.awt.BorderLayout());

        tabBusqueda.setLayout(new java.awt.BorderLayout(5, 5));

        jLabel3.setText("Buscar");
        pBuscar.add(jLabel3);

        cbBusqueda.setMinimumSize(new java.awt.Dimension(51, 25));
        cbBusqueda.setPreferredSize(new java.awt.Dimension(100, 20));
        pBuscar.add(cbBusqueda);

        txcBusqueda.setPreferredSize(new java.awt.Dimension(200, 20));
        txcBusqueda.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txcBusquedaActionPerformed(evt);
            }
        });
        pBuscar.add(txcBusqueda);

        btnBusqueda.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/Gnome-Edit-Find-16.png"))); // NOI18N
        btnBusqueda.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBusquedaActionPerformed(evt);
            }
        });
        pBuscar.add(btnBusqueda);

        tabBusqueda.add(pBuscar, java.awt.BorderLayout.PAGE_START);
        tabBusqueda.add(jLabel2, java.awt.BorderLayout.SOUTH);

        org.jdesktop.swingbinding.JTableBinding jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ, list1, tbParametro, "abcde");
        org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${tbSystparPK.CCodMod}"));
        columnBinding.setColumnName("Modulo");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${CCodIns}"));
        columnBinding.setColumnName("Otro Codigo");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${CDesCor}"));
        columnBinding.setColumnName("Des. Corta");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${CDesLar}"));
        columnBinding.setColumnName("Des. Larga");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${CValMax}"));
        columnBinding.setColumnName("Val Max");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${CValMin}"));
        columnBinding.setColumnName("Val Min");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${CValor}"));
        columnBinding.setColumnName("Valor");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${LActiva}"));
        columnBinding.setColumnName("Activo");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${LValida}"));
        columnBinding.setColumnName("Valida");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${NOrden}"));
        columnBinding.setColumnName("Orden");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${CObserv}"));
        columnBinding.setColumnName("Observ.");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${TModifi}"));
        columnBinding.setColumnName("F. Modificación");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        bindingGroup.addBinding(jTableBinding);
        jTableBinding.bind();
        tbParametro.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tbParametroMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(tbParametro);

        tabBusqueda.add(jScrollPane2, java.awt.BorderLayout.CENTER);

        tabPrincipal.addTab("Búsqueda", tabBusqueda);

        tabEdicion.setLayout(new java.awt.BorderLayout());

        jPanel1.setLayout(new java.awt.GridBagLayout());

        jLabel4.setText("Modulo :");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.ipadx = 1;
        gridBagConstraints.ipady = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(2, 0, 2, 0);
        jPanel1.add(jLabel4, gridBagConstraints);

        jLabel5.setText("Codigo de Tabla :");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.ipadx = 1;
        gridBagConstraints.ipady = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(2, 0, 2, 0);
        jPanel1.add(jLabel5, gridBagConstraints);

        jLabel6.setText("Orden :");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.ipadx = 1;
        gridBagConstraints.ipady = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(2, 0, 2, 0);
        jPanel1.add(jLabel6, gridBagConstraints);

        jLabel7.setText("Codigo :");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.ipadx = 1;
        gridBagConstraints.ipady = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(2, 0, 2, 0);
        jPanel1.add(jLabel7, gridBagConstraints);

        jLabel9.setText("Abreviatura :");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.ipadx = 1;
        gridBagConstraints.ipady = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(2, 0, 2, 0);
        jPanel1.add(jLabel9, gridBagConstraints);

        jLabel10.setText("Descripción :");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.ipadx = 1;
        gridBagConstraints.ipady = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(2, 0, 2, 0);
        jPanel1.add(jLabel10, gridBagConstraints);

        txcCodTab.setColumns(3);

        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tbParametro, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.tbSystparPK.CCodTab}"), txcCodTab, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.ipadx = 1;
        gridBagConstraints.ipady = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(2, 0, 2, 0);
        jPanel1.add(txcCodTab, gridBagConstraints);

        txcCodigo.setColumns(8);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.ipadx = 1;
        gridBagConstraints.ipady = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(2, 0, 2, 0);
        jPanel1.add(txcCodigo, gridBagConstraints);

        txnOrden.setColumns(3);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.ipadx = 1;
        gridBagConstraints.ipady = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(2, 0, 2, 0);
        jPanel1.add(txnOrden, gridBagConstraints);

        txcDesCor.setColumns(10);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.ipadx = 1;
        gridBagConstraints.ipady = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(2, 0, 2, 0);
        jPanel1.add(txcDesCor, gridBagConstraints);

        txcDesLar.setColumns(25);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.ipadx = 1;
        gridBagConstraints.ipady = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(2, 0, 2, 0);
        jPanel1.add(txcDesLar, gridBagConstraints);

        txcValor.setColumns(10);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 6;
        gridBagConstraints.ipadx = 1;
        gridBagConstraints.ipady = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(2, 0, 2, 0);
        jPanel1.add(txcValor, gridBagConstraints);

        jLabel11.setText("Valor :");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 6;
        gridBagConstraints.ipadx = 1;
        gridBagConstraints.ipady = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(2, 0, 2, 0);
        jPanel1.add(jLabel11, gridBagConstraints);

        txcCodIns.setColumns(8);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 7;
        gridBagConstraints.ipadx = 1;
        gridBagConstraints.ipady = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(2, 0, 2, 0);
        jPanel1.add(txcCodIns, gridBagConstraints);

        jLabel12.setText("Codigo equivalente :");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 7;
        gridBagConstraints.ipadx = 1;
        gridBagConstraints.ipady = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(2, 0, 2, 0);
        jPanel1.add(jLabel12, gridBagConstraints);

        txcValMin.setColumns(10);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 8;
        gridBagConstraints.ipadx = 1;
        gridBagConstraints.ipady = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(2, 0, 2, 0);
        jPanel1.add(txcValMin, gridBagConstraints);

        jLabel13.setText("Valor Minimo :");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 8;
        gridBagConstraints.ipadx = 1;
        gridBagConstraints.ipady = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(2, 0, 2, 0);
        jPanel1.add(jLabel13, gridBagConstraints);

        jLabel14.setText("Valor Maximo :");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 9;
        gridBagConstraints.ipadx = 1;
        gridBagConstraints.ipady = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(2, 0, 2, 0);
        jPanel1.add(jLabel14, gridBagConstraints);

        txcValMax.setColumns(10);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 9;
        gridBagConstraints.ipadx = 1;
        gridBagConstraints.ipady = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(2, 0, 2, 0);
        jPanel1.add(txcValMax, gridBagConstraints);

        chkValidar.setText("Validar");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 11;
        gridBagConstraints.ipadx = 1;
        gridBagConstraints.ipady = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(2, 0, 2, 0);
        jPanel1.add(chkValidar, gridBagConstraints);

        chkActivar.setText("Activar");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 11;
        gridBagConstraints.ipadx = 1;
        gridBagConstraints.ipady = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(2, 0, 2, 0);
        jPanel1.add(chkActivar, gridBagConstraints);

        txcObserv.setColumns(25);
        txcObserv.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txcObservActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 10;
        gridBagConstraints.ipadx = 1;
        gridBagConstraints.ipady = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(2, 0, 2, 0);
        jPanel1.add(txcObserv, gridBagConstraints);

        jLabel15.setText("Observación :");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 10;
        gridBagConstraints.ipadx = 1;
        gridBagConstraints.ipady = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(2, 0, 2, 0);
        jPanel1.add(jLabel15, gridBagConstraints);

        cbModulo.setRenderer(new DefaultListCellRenderer() {
            @Override
            public Component getListCellRendererComponent(
                JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
                if (value instanceof TbSystpar) {
                    TbSystpar mec = (TbSystpar)value;
                    setText(mec.getCDesCor());
                }
                return this;
            }
        });

        org.jdesktop.swingbinding.JComboBoxBinding jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, LstModulo, cbModulo, "combo");
        bindingGroup.addBinding(jComboBoxBinding);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.ipadx = 1;
        gridBagConstraints.ipady = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(2, 0, 2, 0);
        jPanel1.add(cbModulo, gridBagConstraints);

        tabEdicion.add(jPanel1, java.awt.BorderLayout.CENTER);

        jPanel6.setLayout(new java.awt.GridBagLayout());

        jPanel4.setBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED));
        jPanel4.setLayout(new java.awt.GridBagLayout());

        jLabel8.setPreferredSize(new java.awt.Dimension(80, 100));
        jPanel4.add(jLabel8, new java.awt.GridBagConstraints());

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        jPanel6.add(jPanel4, gridBagConstraints);

        btnCargaImagen.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/Gnome-Insert-Image-16.png"))); // NOI18N
        btnCargaImagen.setMaximumSize(new java.awt.Dimension(25, 25));
        btnCargaImagen.setMinimumSize(new java.awt.Dimension(25, 25));
        btnCargaImagen.setPreferredSize(new java.awt.Dimension(25, 25));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        jPanel6.add(btnCargaImagen, gridBagConstraints);

        jPanel2.add(jPanel6);

        tabEdicion.add(jPanel2, java.awt.BorderLayout.EAST);

        tabPrincipal.addTab("Edición", tabEdicion);

        pCentro.add(tabPrincipal, java.awt.BorderLayout.CENTER);

        pPrincipal.add(pCentro, java.awt.BorderLayout.CENTER);

        pSur.setLayout(new java.awt.BorderLayout());

        btnGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/Gnome-Media-Floppy-32.png"))); // NOI18N
        btnGuardar.setMnemonic('G');
        btnGuardar.setText("Guardar");
        btnGuardar.setToolTipText("Guardar cambios realizados");
        btnGuardar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnGuardar.setIconTextGap(0);
        btnGuardar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGuardarActionPerformed(evt);
            }
        });
        jPanel5.add(btnGuardar);

        btnNuevo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/Gnome-Document-New-32.png"))); // NOI18N
        btnNuevo.setMnemonic('N');
        btnNuevo.setText("Nuevo");
        btnNuevo.setToolTipText("Nuevo registro");
        btnNuevo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnNuevo.setIconTextGap(0);
        btnNuevo.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnNuevo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNuevoActionPerformed(evt);
            }
        });
        jPanel5.add(btnNuevo);
        btnNuevo.getAccessibleContext().setAccessibleDescription("Nuevo");

        btnEditar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/Gnome-Accessories-Text-Editor-32.png"))); // NOI18N
        btnEditar.setMnemonic('E');
        btnEditar.setText("Editar");
        btnEditar.setToolTipText("Editar registro seleccionado");
        btnEditar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnEditar.setIconTextGap(0);
        btnEditar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnEditar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEditarActionPerformed(evt);
            }
        });
        jPanel5.add(btnEditar);

        btnDeshacer.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/Gnome-Edit-Clear-32.png"))); // NOI18N
        btnDeshacer.setMnemonic('D');
        btnDeshacer.setText("Deshacer");
        btnDeshacer.setToolTipText("Deshacer cambios");
        btnDeshacer.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnDeshacer.setIconTextGap(0);
        btnDeshacer.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnDeshacer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDeshacerActionPerformed(evt);
            }
        });
        jPanel5.add(btnDeshacer);

        btnSalida.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/Gnome-Application-Exit-32.png"))); // NOI18N
        btnSalida.setMnemonic('S');
        btnSalida.setText("Salir");
        btnSalida.setToolTipText("Salir del Mantenimiento");
        btnSalida.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnSalida.setIconTextGap(0);
        btnSalida.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnSalida.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSalidaActionPerformed(evt);
            }
        });
        jPanel5.add(btnSalida);

        pSur.add(jPanel5, java.awt.BorderLayout.EAST);

        lblCodigoVentana.setText("SYS0001");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(lblCodigoVentana, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 193, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addGap(0, 51, Short.MAX_VALUE)
                .addComponent(lblCodigoVentana))
        );

        pSur.add(jPanel3, java.awt.BorderLayout.CENTER);

        pPrincipal.add(pSur, java.awt.BorderLayout.SOUTH);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10);
        getContentPane().add(pPrincipal, gridBagConstraints);

        bindingGroup.bind();

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-700)/2, (screenSize.height-500)/2, 700, 500);
    }// </editor-fold>//GEN-END:initComponents

    private void btnSalidaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSalidaActionPerformed

        this.mxSalir();
    }//GEN-LAST:event_btnSalidaActionPerformed
    private void mxSalir() {

        if (this.poModFor.equals(ModoFormulario.EDICION) || this.poModFor.equals(ModoFormulario.NUEVO)) {
            boolean confirmacion = Mensaje.confirmacion(this, "Se perderan los cambios ¿ esta seguro que desea Salir ?", this.getTitle());
            if (confirmacion) {
                this.dispose();
            }
        }
    }

    private boolean mxValidarDatos() {
        return true;
    }

    private void mxGuardar() {
        TbSystpar loParametro = this.mxExtraerCampos();
        cellStoreController.crearTbSystpar(loParametro);
    }

    private void mxEditar() {
        TbSystpar loParametro = this.mxExtraerCampos();
        cellStoreController.editarTbSystpar(loParametro);
    }

    private void btnGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGuardarActionPerformed

        if (this.mxValidarDatos()) {
            if (this.poModFor.equals(ModoFormulario.NUEVO)) {
                this.mxGuardar();
            } else {
                this.mxEditar();
            }
        }
        this.mxModoFormulario(ModoFormulario.GUARDAR);
    }//GEN-LAST:event_btnGuardarActionPerformed

    private void btnDeshacerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeshacerActionPerformed
        this.mxModoFormulario(ModoFormulario.DESHACER);
        limpiarDatos();
//        txtValor.transferFocus();
    }//GEN-LAST:event_btnDeshacerActionPerformed
    private void mxLLenarCampos(TbSystpar toSystPar) {
        TbSystpar seleccionado = null;
        for (int i = 0; i < LstModulo.size(); i++) {
            TbSystpar modulo = LstModulo.get(i);
            if (modulo.getTbSystparPK().getCCodigo().trim().equals(toSystPar.getTbSystparPK().getCCodMod().trim())) {
                seleccionado = modulo;
                break;
            }
        }

        this.cbModulo.setSelectedItem(seleccionado);
        this.txcCodigo.setText(toSystPar.getTbSystparPK().getCCodigo());
        this.txcCodTab.setText(toSystPar.getTbSystparPK().getCCodTab());
        this.txnOrden.setText(toSystPar.getNOrden());
        this.txcDesCor.setText(toSystPar.getCDesCor());
        this.txcDesLar.setText(toSystPar.getCDesLar());
        this.txcValor.setText(toSystPar.getCValor());
        this.txcCodIns.setText(toSystPar.getCCodIns());
        this.txcValMin.setText(toSystPar.getCValMin());
        this.txcValMax.setText(toSystPar.getCValMax());
        this.txcObserv.setText(toSystPar.getCObserv());
        this.chkActivar.setSelected(toSystPar.getLActiva());
        this.chkValidar.setSelected(toSystPar.getLValida());
    }

    private TbSystpar mxExtraerCampos() {
        TbSystpar loSystPar = new TbSystpar();
        TbSystparPK tbSystparPK = new TbSystparPK();
        loSystPar.setTbSystparPK(tbSystparPK);
        TbSystpar seleccionado = null;
        seleccionado = (TbSystpar) this.cbModulo.getSelectedItem();
        tbSystparPK.setCCodMod(seleccionado.getTbSystparPK().getCCodigo());
        tbSystparPK.setCCodTab(this.txcCodTab.getText());
        tbSystparPK.setCCodigo(this.txcCodigo.getText());
        loSystPar.setNOrden(this.txnOrden.getText());
        loSystPar.setCDesCor(this.txcDesCor.getText());
        loSystPar.setCDesLar(this.txcDesLar.getText());
        loSystPar.setCValor(this.txcValor.getText());
        loSystPar.setCCodIns(this.txcCodIns.getText());
        loSystPar.setCValMin(this.txcValMin.getText());
        loSystPar.setCValMax(this.txcValMax.getText());
        loSystPar.setCObserv(this.txcObserv.getText());
        loSystPar.setLActiva(this.chkActivar.isSelected());
        loSystPar.setLValida(this.chkValidar.isSelected());
        loSystPar.setCCodUsu("0001");
        loSystPar.setTModifi("12/12/2013");
        return loSystPar;
    }

    private void btnEditarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditarActionPerformed
        this.mxModoFormulario(ModoFormulario.EDICION);
        this.mxLLenarCampos(this.LstModulo.get(this.tbParametro.getSelectedRow()));
        // TODO add your handling code here:
    }//GEN-LAST:event_btnEditarActionPerformed

    private void txcBusquedaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txcBusquedaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txcBusquedaActionPerformed

    private void btnBusquedaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBusquedaActionPerformed

        Columna columna = (Columna) cbBusqueda.getSelectedItem();
        String texto = txcBusqueda.getText();
        System.out.println("");
        List<TbSystpar> listaTbSystpar = cellStoreController.obtenerTodosTbSystpar();
        System.out.println(listaTbSystpar);
        mxCargarParametros(listaTbSystpar);
   }//GEN-LAST:event_btnBusquedaActionPerformed
    private void mxCargarParametros(List<TbSystpar> tlstParam) {
        List resultList = beanLista1.getResultList();
        resultList.clear();
        resultList.addAll(tlstParam);
        Binding binding = bindingGroup.getBinding("abcde");
        binding.unbind();
        binding.bind();
        tbParametro.revalidate();


//        lista2.setResultList(tlstParam);
//        Binding get = bindingGroup.getBindings().get(0);
//        get.unbind();
////        System.out.println(list2);
////        for (TbSystpar tbSystpar : tlstParam) {
////            list2.add(tbSystpar);
////        }
//
//        get.bind();
//        //       this.TableParametro
//        //        for (int i = modelo.getDefaultTableModel().getRowCount() - 1; i >= 0; i--) {
//        //            modelo.getDefaultTableModel().removeRow(i);
//        //        }
//        //
//        //        for (TbSystpar tbSystpar : tlstParam) {
//        //            modelo.getDefaultTableModel().addRow(new Object[]{
//        //                        tbSystpar.getTbSystparPK().getCCodMod(),
//        //                        tbSystpar.getTbSystparPK().getCCodMod(),
//        //                        tbSystpar.getAbreviatura(),
//        //                        tbSystpar.getDescripcion()
//        //                    });
//        //        }
    }

    private void btnNuevoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNuevoActionPerformed
        this.mxModoFormulario(ModoFormulario.NUEVO);
        // TODO add your handling code here:
    }//GEN-LAST:event_btnNuevoActionPerformed

    private void formInternalFrameClosing(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameClosing
        // TODO add your handling code here:
        this.mxSalir();
    }//GEN-LAST:event_formInternalFrameClosing

    private void txcObservActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txcObservActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txcObservActionPerformed

    private void tbParametroMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tbParametroMouseClicked
        this.mxModoFormulario(ModoFormulario.SELECCION);
    }//GEN-LAST:event_tbParametroMouseClicked
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private org.cellstore.cliente.gui.model.BeanLista LstBeanModulo;
    private java.util.List<org.cellstore.entidad.TbSystpar> LstModulo;
    private org.cellstore.cliente.gui.model.BeanLista beanLista1;
    private javax.swing.JButton btnBusqueda;
    private javax.swing.JButton btnCargaImagen;
    private javax.swing.JButton btnDeshacer;
    private javax.swing.JButton btnEditar;
    private javax.swing.JButton btnGuardar;
    private javax.swing.JButton btnNuevo;
    private javax.swing.JButton btnSalida;
    private javax.swing.JComboBox cbBusqueda;
    private javax.swing.JComboBox cbModulo;
    private javax.swing.JCheckBox chkActivar;
    private javax.swing.JCheckBox chkValidar;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JLabel lblCodigoVentana;
    private java.util.List<org.cellstore.entidad.TbSystpar> list1;
    private javax.swing.JPanel pBuscar;
    private javax.swing.JPanel pCentro;
    private javax.swing.JPanel pPrincipal;
    private javax.swing.JPanel pSur;
    private javax.swing.JPanel tabBusqueda;
    private javax.swing.JPanel tabEdicion;
    private javax.swing.JTabbedPane tabPrincipal;
    private javax.swing.JTable tbParametro;
    private org.palituxd.tools.swing.CTextField txcBusqueda;
    private org.palituxd.tools.swing.CTextField txcCodIns;
    private org.palituxd.tools.swing.CTextField txcCodTab;
    private org.palituxd.tools.swing.CTextField txcCodigo;
    private org.palituxd.tools.swing.CTextField txcDesCor;
    private org.palituxd.tools.swing.CTextField txcDesLar;
    private org.palituxd.tools.swing.CTextField txcObserv;
    private org.palituxd.tools.swing.CTextField txcValMax;
    private org.palituxd.tools.swing.CTextField txcValMin;
    private org.palituxd.tools.swing.CTextField txcValor;
    private org.palituxd.tools.swing.CTextField txnOrden;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables
}
